package com.cskaoyan.config;

import com.cskaoyan.interceptor.HandlerInterceptor1;
import com.cskaoyan.interceptor.HandlerInterceptor2;
import com.cskaoyan.interceptor.HandlerInterceptor5;
import com.cskaoyan.interceptor.UserHandlerInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 楚夏三分
 * @datetime 2022/12/26 20:44
 * @description: TODO: 设置静态资源处理器 \ Interceptors
 */
@ComponentScan("com.cskaoyan.controller")
@EnableWebMvc
public class ServletConfiguration implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pic/**").addResourceLocations("/");
        registry.addResourceHandler("/pic2/**").addResourceLocations("classpath:/");
        registry.addResourceHandler("/pic3/**").addResourceLocations("file:C:/app/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new HandlerInterceptor1()).addPathPatterns("/hellosy");
        registry.addInterceptor(new HandlerInterceptor2()).addPathPatterns("/hellosy/**");
        registry.addInterceptor(new HandlerInterceptor5()).addPathPatterns("/**");
        registry.addInterceptor(new UserHandlerInterceptor()).addPathPatterns("/user/**");
    }
}
